# -*- coding: utf-8 -*-
from django import template
from django.conf import settings

from pygameweb.notification.models import Subscription, CHOICES as choices

register = template.Library()


@register.simple_tag
def subscription_link(request, kind, obj_id=None, add_id=False):
    if request.user.is_anonymous():
        return ""
    subscribed = Subscription.objects.subscribed(request.user, kind, obj_id)
    return (('<a class="%(sub)sscribe-link" '
             +'href="?%(sub)ssubscribe=%(kind)s%(id)s" '
             + 'onclick="ajax_subscribe(this);return false;">'
             + '<img src="%(media_url)simages/%(sub)ssubscribe_icon.png" '
             + 'title="%(sub)ssubscribe %(kind)s" alt="[@]"/></a>') % 
                          {"sub": "un" if subscribed else "",
                           "id": "&id=%s" % obj_id if add_id and obj_id else "",
                           "kind": choices[kind].replace(" ", "-"),
                           "media_url": settings.MEDIA_URL})
subscription_link.allow_tags = True
    
        